package com.example.androidkt.fifth

import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider

class VIewModelFactory {
    class VMfactroy(private val count: Int) : ViewModelProvider.Factory {
        override fun <T : ViewModel> create(modelClass: Class<T>): T {
            if (modelClass.isAssignableFrom(ViewModelOne::class.java)) {
                return ViewModelOne() as T
            } else if (modelClass.isAssignableFrom(ViewModelTwo::class.java)) {
                return ViewModelTwo(count) as T
            } else {
                throw ClassNotFoundException("class $modelClass viewmodel没有注册到工厂类")
            }
        }
    }
}